import java.util.Arrays;
import java.util.Scanner;

public class NGuessNumber {
    public static int[] generateAnswer() {
        int[] arr = new int[4];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 9 + 1);
        }
        for (int j = 1; j < arr.length; j++) {
            for (int i = 0; i < j; i++) {
                if (arr[j] == arr[i]) {
                    arr[j] = (int) (Math.random() * 9 + 1);
                    j--;
                }
            }
        }
        return arr;
    }
    public static int[] getPlayerInput(int guessdate[]) {
        //接收玩家输入的4个数字并返回。
        int guess[] = guessdate;
        return guess;
    }

    public static String compareGuessAnswer(int[] numbers, int guesslist[]) {
        int A_count = 0;
        int B_count = 0;
        //比较玩家猜测和答案后返回提示信息。
        //A 存在且位置正确，B 存在且位置不正确 1A1B 1表示数量
        for (int i = 0; i < numbers.length; i++) {
            for (int l = 0; l < numbers.length; l++) {
                if (i != l) {
                    if (numbers[i] == guesslist[l]) {
                       B_count++;
                    }
                } else {
                    if (numbers[i] == guesslist[l]) {
                        A_count++;
                    }
                }

            }
        }
        System.out.println(A_count + "A" + B_count + "B");
        return A_count + "A" + B_count + "B";
    }
    public static boolean isWin(String bj){
        return bj.contains("4A");
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int arr[] = new int[4];
        while (true){
            int zd[] = generateAnswer();
            System.out.print("答案：");
            for (int i :zd){
                System.out.print(i);}
            System.out.println("");
        while (true) {
            System.out.println("A表示存在且位置正确的数字个数，B表示存在但位置不正确的位置个数");
            System.out.println("如：1A2B 代表猜测的三个数字是对的有一个位置对，有两个位置不对");
            System.out.println("请输入四个字");
            for (int i = 0; i < 4; i++) {
                arr[i] = scanner.nextInt();
            }
            if (isWin(compareGuessAnswer(zd, arr))) {
                break;
            }

        }
            System.out.println("是否在玩一局(0:在玩，1：退出)");
        int again = scanner.nextInt();
        if (again==1){
            break;
        }
    }
    }
}
